package service

import (
	"sync"

	"gitee.com/crack007/goose/gscore/server"
)

var proxySessionMap = sync.Map{}

func NewProxySession(session *server.Session) *ProxySession {
	proxySession := &ProxySession{
		clientMsgChan:    make(chan []byte, 10),
		proxyConnectChan: make(chan struct{}),
		clientSession:    session,
	}
	return proxySession
}

func CreateProxySession(session *server.Session) *ProxySession {
	proxySession := NewProxySession(session)
	proxySessionMap.LoadOrStore(session.SessionId, proxySession)
	return proxySession
}

func GetProxySession(session *server.Session) *ProxySession {
	value, ok := proxySessionMap.Load(session.SessionId)
	if ok {
		return value.(*ProxySession)
	}
	return nil
}

func RemoveProxySession(session *server.Session) {
	proxySessionMap.Delete(session.SessionId)
}
